home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_023 / ver30 / tty / amigados / tty.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  283 lines

  1. /*
  2.  * Name:    MicroEMACS
  3.  *        Amiga console device virtual terminal display
  4.  * Version:    31
  5.  * Last Edit:    21-Apr-86
  6.  * Created:    19-Apr-86 ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  7.  * Modified:    21-Apr-86 ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  8.  *        In ttresize() use ttmove(HUGE,HUGE) and cursor
  9.  *        position report to get the new window size 
  10.  */
  11.  
  12. #include    "def.h"
  13.  
  14.  
  15. #define    BEL    0x07            /* BEL character.        */
  16. #define    ESC    0x1B            /* ESC character.        */
  17.  
  18. extern    int    ttrow;
  19. extern    int    ttcol;
  20. extern    int    tttop;
  21. extern    int    ttbot;
  22. extern    int    tthue;
  23.  
  24. int    tceeol    =    3;        /* Costs, ANSI display.        */
  25. int    tcinsl    =     17;
  26. int    tcdell    =    16;
  27.  
  28. /*
  29.  * Initialize the terminal when the editor
  30.  * gets started up. This is a no-op on the Amiga.
  31.  */
  32. ttinit()
  33. {
  34. }
  35.  
  36. /*
  37.  * Clean up the terminal, in anticipation of
  38.  * a return to the command interpreter. This is a no-op
  39.  * on the Amiga.
  40.  */
  41. tttidy()
  42. {
  43. }
  44.  
  45. /*
  46.  * Move the cursor to the specified
  47.  * origin 0 row and column position. Try to
  48.  * optimize out extra moves; redisplay may
  49.  * have left the cursor in the right
  50.  * location last time!
  51.  */
  52. ttmove(row, col)
  53. {
  54.     if (ttrow!=row || ttcol!=col) {
  55.         ttputc(ESC);
  56.         ttputc('[');
  57.         asciiparm(row+1);
  58.         ttputc(';');
  59.         asciiparm(col+1);
  60.         ttputc('H');
  61.         ttrow = row;
  62.         ttcol = col;
  63.     }
  64. }
  65.  
  66. /*
  67.  * Erase to end of line.
  68.  */
  69. tteeol()
  70. {
  71.     ttputc(ESC);
  72.     ttputc('[');
  73.     ttputc('K');
  74. }
  75.  
  76. /*
  77.  * Erase to end of page.
  78.  */
  79. tteeop()
  80. {
  81.     ttputc(ESC);
  82.     ttputc('[');
  83.     ttputc('J');
  84. }
  85.  
  86. /*
  87.  * Make a noise.
  88.  */
  89. ttbeep()
  90. {
  91.     ttputc(BEL);
  92.     ttflush();
  93. }
  94.  
  95. /*
  96.  * Convert a number to decimal
  97.  * ascii, and write it out. Used to
  98.  * deal with numeric arguments.
  99.  */
  100. asciiparm(n)
  101. register int    n;
  102. {
  103.     register int    q;
  104.  
  105.     q = n/10;
  106.     if (q != 0)
  107.         asciiparm(q);
  108.     ttputc((n%10) + '0');
  109. }
  110.  
  111. /*
  112.  * Insert a block of blank lines onto the
  113.  * screen, using a scrolling region that starts at row
  114.  * "row" and extends down to row "bot". Deal with the one
  115.  * line case, which is a little bit special, with special
  116.  * case code.
  117.  *
  118.  * Since we don't really have a scrolling region,
  119.  * delete the block of lines that would have been deleted if
  120.  * we'd had one, then insert blank lines to move the rest
  121.  * of the screen back to where it belongs.  This idea from
  122.  * the Heath driver.
  123.  */
  124. ttinsl(row, bot, nchunk)
  125. {
  126.     register int    i;
  127.  
  128.     if (row == bot) {            /* Funny case.        */
  129.         if (nchunk != 1)
  130.             abort();
  131.         ttmove(row, 0);
  132.         tteeol();
  133.         return;
  134.     } 
  135.     ttmove(1+bot-nchunk, 0);
  136.     if (nchunk > 0) {        /* Delete a chunk of lines    */
  137.         ttputc(ESC);        /* nchunk in size.  Rest of    */
  138.         ttputc('[');        /* screen moves up.        */
  139.         asciiparm(nchunk);
  140.         ttputc('M');
  141.     }
  142.     ttmove(row, 0);
  143.     if (nchunk > 0) {        /* Insert a chunk nchunk in size*/
  144.         ttputc(ESC);        /* before current line,    sliding    */
  145.         ttputc('[');        /* rest of screen down.        */
  146.         asciiparm(nchunk);
  147.         ttputc('L');
  148.     }
  149.     ttrow = row;            /* End up on current line    */
  150.     ttcol = 0;
  151. }
  152.  
  153. /*
  154.  * Delete a block of lines, with the uppermost
  155.  * line at row "row", in a screen slice that extends to
  156.  * row "bot". The "nchunk" is the number of lines that have
  157.  * to be deleted.  This is done by deleting nchunk lines at
  158.  * the appropriate spot, then inserting nchunk lines to make
  159.  * up for the empty space at the bottom of the virtual scrolling
  160.  * region.
  161.  */
  162. ttdell(row, bot, nchunk)
  163. {
  164.     register int    i;
  165.  
  166.     if (row == bot) {        /* One line special case    */
  167.         ttmove(row, 0);
  168.         tteeol();
  169.         return;
  170.     }
  171.     if (nchunk > 0) {
  172.         ttmove(row, 0);
  173.         ttputc(ESC);
  174.         ttputc('[');
  175.         asciiparm(nchunk);
  176.         ttputc('M');
  177.     }
  178.     ttmove(1+bot-nchunk,0);
  179.     if (nchunk > 0) {
  180.         ttputc(ESC);        /* For all lines in chunk    */
  181.         ttputc('[');        /* INS line before bottom    */
  182.         asciiparm(nchunk);    /* Bottom of window (and rest     */
  183.         ttputc('L');        /* of screen) moves down */
  184.     }
  185.     ttrow = HUGE;            /* Force ttmove() to do the move*/
  186.     ttcol = HUGE;
  187.     ttmove(bot-nchunk,0);
  188. }
  189.  
  190. /*
  191.  * No-op.
  192.  */
  193. ttwindow(top,bot)
  194. {
  195. }
  196.  
  197. /*
  198.  * No-op.
  199.  */
  200. ttnowindow()
  201. {
  202. }
  203.  
  204. /*
  205.  * Set the current writing color to the
  206.  * specified color. Watch for color changes that are
  207.  * not going to do anything (the color is already right)
  208.  * and don't send anything to the display.
  209.  */
  210. ttcolor(color)
  211. register int    color;
  212. {
  213.     if (color != tthue) {
  214.         if (color == CTEXT) {        /* Normal video.    */
  215.             ttputc(ESC);
  216.             ttputc('[');
  217.             ttputc('m');
  218.         } else if (color == CMODE) {    /* Reverse video.    */
  219.             ttputc(ESC);
  220.             ttputc('[');
  221.             ttputc('7');
  222.             ttputc('m');
  223.         }
  224.         tthue = color;            /* Save the color.    */
  225.     }
  226. }
  227.  
  228. /*
  229.  * This routine is called by the
  230.  * "refresh the screen" command to try and resize
  231.  * the display. The new size, which must be deadstopped
  232.  * to not exceed the NROW and NCOL limits, is stored
  233.  * back into "nrow" and "ncol". Display can always deal
  234.  * with a screen NROW by NCOL. Look in "window.c" to
  235.  * see how the caller deals with a change.
  236.  */
  237. #define    CSI    0x9B
  238.  
  239. ttresize()
  240. {
  241.     register int newnrow, newncol;
  242.  
  243.     ttmove(HUGE,HUGE);        /* Go to bottom right        */
  244.     ttputc(CSI);            /* See where cursor went to    */
  245.     ttputc('6');
  246.     ttputc('n');
  247.     ttflush();
  248.  
  249.     if (ttgetc() != CSI)            /* parse the report     */
  250.         return;
  251.     if ((newnrow = readparm(';')) == -1)
  252.         return;
  253.     if ((newncol = readparm('R')) == -1)
  254.         return;
  255.  
  256.     if (newnrow < 1)            /* check limits.    */
  257.         newnrow = 1;
  258.     else if (newnrow > NROW)
  259.         newnrow = NROW;
  260.     if (newncol < 1)
  261.         newncol = 1;
  262.     else if (newncol > NCOL)
  263.         newncol = NCOL;
  264.     nrow = newnrow;
  265.     ncol = newncol;
  266. }
  267.  
  268. /*
  269.  * Read an unsigned number from the terminal
  270.  */
  271. static readparm(delim)
  272. char delim;
  273. {
  274.     register int     parm;
  275.     register int    c;
  276.  
  277.     parm = 0;
  278.     while ((c=ttgetc()) >= '0' && c <= '9')
  279.         parm = 10 * parm + c - '0';
  280.     return (c == delim) ? parm : -1;
  281. }
  282.  
  283.